def get_given_answer(n, request):
    given_answer = -1
    counter = 0;
    for i in range(0, 3):
        if request.get("gruppe"+str(n)+"_"+str(i)):
            given_answer = i
            counter += 1
    if counter > 1:
        given_answer = -2;
    return given_answer

def list_comparator(lCorrect, lGiven):
    matches = 0
    length = min([len(lCorrect), len(lGiven)])
    for idx in range(0, length):
        if lCorrect[idx] == lGiven[idx]:
            matches += 1
    return matches

def examination_score(lCorrect, lGiven):
    score = 0
    lenCorrect = len(lCorrect)
    lenGiven   = len(lGiven) 
    if ((lenCorrect <= 0) or (lenGiven > lenCorrect)):
         raise ValueError("Use better values")
    for idx in range(0, lenCorrect):
        if lCorrect[idx] == lGiven[idx]:
            score += 1
    score = 10 * (float(score) / float(lenCorrect))      
    return score

def correct_answer(this):
    return this.alternatives[this.correct]

def is_in_time(start_time, stop_time, duration_minutes):
    delta = stop_time - start_time
    allowed_period = duration_minutes * 60
    # allow 10 extra seconds....
    allowed_period += 10  
    if delta.seconds <= allowed_period:
        return True
    else:
        return False
